package com.ztt.service.impl;

import com.ztt.pojo.entity.zttPurchase;
import com.ztt.mapper.PurchaseMapper;
import com.ztt.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PurchaseServiceImpl implements PurchaseService {

    @Autowired
    private PurchaseMapper purchaseMapper;

    @Override
    public List<zttPurchase> selectAllPurchase(){
        return purchaseMapper.selectAllPurchase();
    };

    @Override
    public void insertPurchase(zttPurchase purchase){
        purchaseMapper.insertPurchase(purchase);
    };

    @Override
    public zttPurchase getPurchaseById(zttPurchase purchase) {
        return purchaseMapper.getPurchaseById(purchase);
    }

    @Override
    public List<zttPurchase> getPurchaseByEmployeeId(zttPurchase purchase) {
        return purchaseMapper.getPurchaseByEmployeeId(purchase);
    }


    @Override
    public void updatePurchase(zttPurchase purchase) {
        zttPurchase purchase1 = purchaseMapper.getPurchaseById(purchase);
        System.out.println(purchase1);
        if(purchase.getPurchaseQuantity() != purchase1.getPurchaseQuantity()){
            purchase1.setPurchaseQuantity(purchase.getPurchaseQuantity());
        }
        if(purchase.getPurchaseTotalPrice()!=purchase1.getPurchaseTotalPrice()){
            purchase1.setPurchaseTotalPrice(purchase.getPurchaseTotalPrice());
        }
        if(!purchase.getPurchaseTime().equals("")){
            purchase1.setPurchaseTime(purchase.getPurchaseTime());
        }
        if (!purchase.getNotes().equals("")){
            purchase1.setNotes(purchase.getNotes());
        }
        purchaseMapper.updatePurchase(purchase1);
    }

    @Override
    public void deletePurchase(zttPurchase purchase) {

        purchaseMapper.deletePurchase(purchase);
    }

}
